// events.js
var events = require("events");

var eventEmitter = new events.EventEmitter();

var listner1 = function(){
	console.log("listner1 executed!");
}

var listner2 = function(){
	console.log("listner2 executed!");
}

eventEmitter.addListener("connection",listner1);

eventEmitter.on("connection",listner2);

var eventListeners = require("events").EventEmitter.listenerCount(eventEmitter,"connection");
console.log("eventListeners count: "+eventListeners);

eventEmitter.emit("connection");

eventEmitter.removeListener("connection",listner1);
console.log("listner1 will not listen now!");

eventListeners = require("events").EventEmitter.listenerCount(eventEmitter,"connection");
console.log("eventListeners count: "+eventListeners);
eventEmitter.emit("connection");

console.log("the end!");